package com.example.hm_dtfkz.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.webkit.WebSettings;

import androidx.viewbinding.ViewBinding;

import com.example.hm_dtfkz.R;
import com.example.hm_dtfkz.databinding.ActivityUserServiceAgreementBinding;
import com.example.hm_dtfkz.ui.base.VBBaseActivity;
import com.example.hm_dtfkz.util.ActivityClickUtil;


public class UserServiceAgreementActivity extends VBBaseActivity implements View.OnClickListener {

    public static volatile int TYPE_USER = 0;
    public static volatile int TYPE_PRIVACY = 1;
    private static final String TYPE = "type";

    public static void startAct(Activity activity, int type) {
        Intent intent = new Intent(activity, UserServiceAgreementActivity.class);
        intent.putExtra(TYPE, type);
        activity.startActivity(intent);
    }

    private ActivityUserServiceAgreementBinding agreementBinding;

    @Override
    public ViewBinding getViewBinding() {
        setTitleBackground(BG_BLACK);
        return agreementBinding = ActivityUserServiceAgreementBinding.inflate(getLayoutInflater());
    }

    @Override
    public void initView() {
        super.initView();
        ActivityClickUtil.getInstance().clear();

        int type = getIntent().getIntExtra(TYPE, 0);
        WebSettings settings = agreementBinding.webView.getSettings();
        // 设置缩放
        settings.setBuiltInZoomControls(false);
        // 使页面适应用户屏幕
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        // 开启JavaScript
        settings.setJavaScriptEnabled(true);
        agreementBinding.webView.setVerticalScrollBarEnabled(false);//隐藏垂直滚动条
        if (type == 0) { //用户协议
            agreementBinding.tvTitle.setText("用户协议");
            //用户协议
            String getAssetsUser = "file:///android_asset/index_user.html";
            agreementBinding.webView.loadUrl(getAssetsUser);
        } else if (type == 1) { //隐私协议
            agreementBinding.tvTitle.setText("隐私政策");
            //隐私政策
            String getAssetsPrivacy = "file:///android_asset/index_policy.html";
            agreementBinding.webView.loadUrl(getAssetsPrivacy);
        }
    }

    @Override
    public void initLister() {
        super.initLister();
        agreementBinding.imgBack.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (ActivityClickUtil.getInstance().isFastClick()) {
            //防止用户快速点击
            return;
        }
        if (v.getId() == R.id.imgBack) {
            finish();
        }
    }
}